﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace admin.infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class UpdateCreate : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_AppPermission_AppRole_AppRoleId",
                table: "AppPermission");

            migrationBuilder.DropIndex(
                name: "IX_AppPermission_AppRoleId",
                table: "AppPermission");

            migrationBuilder.DropColumn(
                name: "AppRoleId",
                table: "AppPermission");

            migrationBuilder.CreateTable(
                name: "AppPermissionAppRole",
                columns: table => new
                {
                    PermissionsId = table.Column<Guid>(type: "uuid", nullable: false),
                    RolesId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_AppPermissionAppRole", x => new { x.PermissionsId, x.RolesId });
                    table.ForeignKey(
                        name: "FK_AppPermissionAppRole_AppPermission_PermissionsId",
                        column: x => x.PermissionsId,
                        principalTable: "AppPermission",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_AppPermissionAppRole_AppRole_RolesId",
                        column: x => x.RolesId,
                        principalTable: "AppRole",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_AppPermissionAppRole_RolesId",
                table: "AppPermissionAppRole",
                column: "RolesId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "AppPermissionAppRole");

            migrationBuilder.AddColumn<Guid>(
                name: "AppRoleId",
                table: "AppPermission",
                type: "uuid",
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_AppPermission_AppRoleId",
                table: "AppPermission",
                column: "AppRoleId");

            migrationBuilder.AddForeignKey(
                name: "FK_AppPermission_AppRole_AppRoleId",
                table: "AppPermission",
                column: "AppRoleId",
                principalTable: "AppRole",
                principalColumn: "Id");
        }
    }
}
